#include "ModUtils.h"

using namespace Ogre;

void MatrixFromAxisAngle(Matrix4& mat, const Vector3& vNormAxis, float angle) 
{
	float c = cos(angle);
	float s = sin(angle);
	float t = 1.0 - c;

	mat = Matrix4::IDENTITY;
	mat[0][0] = c + vNormAxis.x * vNormAxis.x * t;
	mat[1][1] = c + vNormAxis.y * vNormAxis.y * t;
	mat[2][2] = c + vNormAxis.z * vNormAxis.z * t;

	float tmp1 = vNormAxis.x * vNormAxis.y * t;
	float tmp2 = vNormAxis.z * s;
	mat[1][0] = tmp1 + tmp2;
	mat[0][1] = tmp1 - tmp2;

	tmp1 = vNormAxis.x * vNormAxis.z * t;
	tmp2 = vNormAxis.y * s;
	mat[2][0] = tmp1 - tmp2;
	mat[0][2] = tmp1 + tmp2;    

	tmp1 = vNormAxis.y * vNormAxis.z * t;
	tmp2 = vNormAxis.x * s;
	mat[2][1] = tmp1 + tmp2;
	mat[1][2] = tmp1 - tmp2;
}